package com.meixiang.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.meixiang.R;
import com.meixiang.activity.moments.PostDetailsActivity;
import com.meixiang.view.CircleImageView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 作者：黑哥 on 2016/5/16 18:08
 */
public class MyConcernAdapter extends RecyclerView.Adapter<MyConcernAdapter.ViewHolder> {

    private Context context;

    public MyConcernAdapter(Context context) {
        this.context = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.list_concern_item, parent, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        if (mOnItemClickListener != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int pos = holder.getLayoutPosition();
                    mOnItemClickListener.onItemClick(holder.itemView, pos);

                }
            });
        }
        ((ViewHolder) holder).mTvCheckDetails.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.startActivity(new Intent(context, PostDetailsActivity.class));
            }
        });
    }

    @Override
    public int getItemCount() {
        return 4;
    }

    private OnItemClickListener mOnItemClickListener;

    public void setOnItemClickListener(OnItemClickListener mOnItemClickListener) {
        this.mOnItemClickListener = mOnItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @Bind(R.id.iv_user_portrait)
        CircleImageView mIvUserPortrait;
        @Bind(R.id.tv_user_name)
        TextView mTvUserName;
        @Bind(R.id.tv_content)
        TextView mTvContent;
        @Bind(R.id.tv_check_details)
        TextView mTvCheckDetails;
        @Bind(R.id.tv_time)
        TextView mTvTime;
        @Bind(R.id.iv_like)
        ImageView mIvLike;
        @Bind(R.id.tv_like)
        TextView mTvLike;
        @Bind(R.id.iv_message)
        ImageView mIvMessage;
        @Bind(R.id.tv_message)
        TextView mTvMessage;


        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
